Add User Attributes to Your Integration
User attributes help provide additional context about the user, session, or request, which then allows for the use of additional strategies and merchandising rules.
JavaScript Integration
How to Make this Code Work for You?
-
Create the integration code on each of the pages on your site by following the JSON integration guides.
-
Add this function to your integration code:
Function | Requirement |
---|---|
R3_COMMON.addContext(CONTEXT) | Replace CONTEXT with a JSON object that defines custom key/value pairs that describe the user context. See the examples below. |
Sample Code
Call addContext() in the Primary Code Block.
JSON
Copy
<!-- Place code inside the <body> element as close to the top as possible -->
<script charset="utf-8" type="text/javascript">
var R3_COMMON = new r3_common();
R3_COMMON.setApiKey('abcd5432e1');
R3_COMMON.setBaseUrl(window.location.protocol+'//integration.richrelevance.com/rrserver/');
R3_COMMON.setClickthruServer(window.location.protocol+"//"+window.location.host);
R3_COMMON.setSessionId('6B4D397B');
R3_COMMON.setUserId('10987'); // if exists, set it; if not, set it as session ID
// here's an example requesting recommendations for 1 page area
R3_COMMON.addPlacementType('home_page.rr1');
var R3_HOME = new r3_home();
// Adding User Attribute data via .addContext()
// Ex1: single object
R3_COMMON.addContext({
"userAttribute":{
"fav_color": ["red", "green"],
"hair_color": "brown"
}
});
// Ex2: multiple calls
R3_COMMON.addContext({
"userAttribute": {"fav_color": ["red", "green"]}
});
R3_COMMON.addContext({
"userAttribute": {"hair_color": "brown"}
});
rr_flush_onload();
r3();
</script>
APIs
Set the registry type with the userAttribute parameter in recsForPlacements.
Example: userAttribute=fav_color:red;green|hair_color:brown